package com.ruoyi.web.controller.self;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.self.domain.RmTest;
import com.ruoyi.self.service.IRmTestService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 考卷信息Controller
 * 
 * @author ruoyi
 * @date 2019-11-26
 */
@Controller
@RequestMapping("/self/test")
public class RmTestController extends BaseController
{
    private String prefix = "self/test";

    @Autowired
    private IRmTestService rmTestService;

    @RequiresPermissions("self:test:view")
    @GetMapping()
    public String test()
    {
        return prefix + "/test";
    }

    /*@RequiresPermissions("self:test:view")*/
    @GetMapping("/profile/{id}/{testType}")
    public String testtxt(@PathVariable("id") String id, @PathVariable("testType") String testType, ModelMap mmap)
    {
        System.out.println(id + "??" + testType);
        mmap.put("id", id);
        mmap.put("testType", testType);
        return prefix + "/profile/profile";
    }



    /**
     * 查询考卷信息列表
     */
    @RequiresPermissions("self:test:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RmTest rmTest)
    {
        startPage();
        List<RmTest> list = rmTestService.selectRmTestList(rmTest);
        return getDataTable(list);
    }

    /**
     * 导出考卷信息列表
     */
    @RequiresPermissions("self:test:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RmTest rmTest)
    {
        List<RmTest> list = rmTestService.selectRmTestList(rmTest);
        ExcelUtil<RmTest> util = new ExcelUtil<RmTest>(RmTest.class);
        return util.exportExcel(list, "test");
    }

    /**
     * 新增考卷信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存考卷信息
     */
    @RequiresPermissions("self:test:add")
    @Log(title = "考卷信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RmTest rmTest)
    {
        return toAjax(rmTestService.insertRmTest(rmTest));
    }

    /**
     * 修改考卷信息
     */
    @GetMapping("/edit/{tid}")
    public String edit(@PathVariable("tid") Long tid, ModelMap mmap)
    {
        RmTest rmTest = rmTestService.selectRmTestById(tid);
        mmap.put("rmTest", rmTest);
        return prefix + "/edit";
    }

    /**
     * 修改保存考卷信息
     */
    @RequiresPermissions("self:test:edit")
    @Log(title = "考卷信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RmTest rmTest)
    {
        return toAjax(rmTestService.updateRmTest(rmTest));
    }

    /**
     * 删除考卷信息
     */
    @RequiresPermissions("self:test:remove")
    @Log(title = "考卷信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rmTestService.deleteRmTestByIds(ids));
    }

    /**
     * 查询考卷详细
     */
    @RequiresPermissions("self:test:list")
    @GetMapping("/detail/{tid}")
    public String detail(@PathVariable("tid") long tid, ModelMap mmap)
    {
        mmap.put("test", rmTestService.selectRmTestById(tid));
   /*     mmap.put("dictList", rmTestService.selectDictTypeAll());*/
        return "self/testinfo/testinfo";
    }
}
